package converter;

import java.io.DataOutputStream;
import java.io.IOException;
import java.util.HashMap;

public class Sprite {
	private String name;
	private int x;
	private int y;
	private String type; /*0: unk, 1: hero, 2: wall**/
	private int height;
	private int width;
	private java.util.Map<String, String> properties = new HashMap<String, String>();
	
	
	protected String getName() {
		return name;
	}
	protected void setName(String name) {
		this.name = name;
	}
	protected int getX() {
		return x;
	}
	protected void setX(int x) {
		this.x = x;
	}
	protected int getY() {
		return y;
	}
	protected void setY(int y) {
		this.y = y;
	}
	public void save(DataOutputStream file) {
		try {
			file.writeUTF(name);
			int iType = getIType();
			file.writeInt(iType);
			file.writeInt(x);
			file.writeInt(y);
			file.writeInt(width);
			file.writeInt(height);
			switch (iType) {
			case 1:
				file.writeByte(getFaceDir() );
				break;
			case 3:
				file.writeByte(getFaceDir());
				file.writeUTF(getImage());
				file.writeUTF(getMensage());
				break;
			default:
				break;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	private String getMensage() {
		String mensage = properties.get("mensage");
		return mensage!=null?mensage:"";
	}
	private String getImage() {
		String image = properties.get("image");
		return image!=null?image:"";
	}
	private int getFaceDir() {
		String faceDir = properties.get("face-dir");
		if(faceDir==null) return 0;
		if(faceDir.equalsIgnoreCase("DOWN")) return 0;
		if(faceDir.equalsIgnoreCase("RIGHT")) return 1;
		if(faceDir.equalsIgnoreCase("UP")) return 2;
		if(faceDir.equalsIgnoreCase("LEFT")) return 3;
		return 0;
	}
	private int getIType() {
		if(type.equalsIgnoreCase("hero")) return 1;
		if(type.equalsIgnoreCase("wall")) return 2;
		if(type.equalsIgnoreCase("talker")) return 3;
		return 0;
	}
	public void setType(String type) {
		this.type = type;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public void addProperty(String pType, String pValue) {
		properties.put(pType, pValue);
	}
	
}
